package com.bindingfly.client.formrender.factory;

import java.util.HashMap;

import com.bindingfly.client.formrender.WidgetInjecterPojo;
import com.bindingfly.client.formrender.widget.types.InjectableWidget;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Widget;

public class WidgetFactor
{

	public static final HashMap<String, InjectableWidget> injectableWidgets = new HashMap<String, InjectableWidget>();
	public static final HashMap<String, InjectableWidget> injectableContainers = new HashMap<String, InjectableWidget>();
	
	public static WidgetInjecterPojo generateWidget(Element rootWidgetElement, boolean lookingForContainers)
	{

		

		Widget widget = null;

		InjectableWidget injectableWidget = null;
		
		String type = null;
		
		if (lookingForContainers)
		{
			type = rootWidgetElement.getAttribute("widgetContainerType");
			injectableWidget = injectableContainers.get(type);
		}else
		{	
			type = rootWidgetElement.getAttribute("widgetType");
			injectableWidget = injectableWidgets.get(type);
		}
		
		if (injectableWidget != null)
		{
			widget = injectableWidget.init(rootWidgetElement);
			return new WidgetInjecterPojo(widget, injectableWidget);
		} else
		{
			System.out.println("Unknown injectableWidget type: " + type);
		}
		
		return null;
		
		
	}

	public static WidgetInjecterPojo generateWidgetContainer(Element possibleWidget)
	{
		return generateWidget(possibleWidget, true);
	}
}
